package com.vpx.server.controller.system;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vpx.server.framework.base.ResultMsg;
import com.vpx.server.service.system.SqlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/report")
@Api(tags = "附件管理")
public class SqlExecuteController {
    @Resource
    SqlService sqlService;

    @ApiOperation("执行数据查询分页")
    @PostMapping("/query_page")
    public ResultMsg<Page<JSONObject>> queryPage(@RequestBody Map<String, Object> param) {
        return ResultMsg.success(sqlService.findPageObj((String)param.get("key_code"),param));
    }

    @ApiOperation("执行数据查询")
    @PostMapping("/query_list")
    public ResultMsg<List<JSONObject>> queryList(@RequestBody Map<String, Object> param) {
        return ResultMsg.success(sqlService.findListObject((String)param.get("key_code"),param,JSONObject.class));
    }
    @ApiOperation("查询单个数据详情")
    @PostMapping("/query_obj")
    public ResultMsg<JSONObject> queryOne(@RequestBody Map<String, Object> param) {
        return ResultMsg.success(sqlService.findOneObject((String)param.get("key_code"),param,JSONObject.class));
    }
    @ApiOperation("执行更新或者删除")
    @PostMapping("/execute")
    public ResultMsg<Integer> execute(@RequestBody Map<String, Object> param) {
        return ResultMsg.success(sqlService.execute((String)param.get("key_code"),param));
    }
}
